package java06;

import java.util.Scanner;
class ArrayUtils{
    public static double findMax(double[] arr,int begin, int end)throws IllegalArgumentException{
        if(begin>=end)
            throw new IllegalArgumentException("begin:"+begin+" >= end:"+end);
        if(begin<0)
            throw new IllegalArgumentException("begin:"+begin+" < 0");
        if(end>arr.length)
            throw new IllegalArgumentException("end:"+end+" > arr.length");
        double d=arr[begin];
            for(int j=begin+1;j<=end-1;j++){
                if(d<arr[j])d=arr[j];
            }
        return d;
    }
}
public class Java060503 {

    public static void main(String[] args)throws IllegalArgumentException{
        // TODO Auto-generated method stub
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        double[] arr=new double[n];
        for(int i=0;i<arr.length;i++){
            arr[i]=in.nextDouble();
        }
        while(in.hasNextInt()){
            int begin=in.nextInt();
            int end=in.nextInt();
            double max=0;
            try{
                max=ArrayUtils.findMax(arr, begin, end);
                System.out.println(max);
            }catch(IllegalArgumentException e){
                System.out.println(e);
            }
        }
        try {
                 System.out.println(ArrayUtils.class.getDeclaredMethod("findMax", double[].class,int.class,int.class));
            } catch (Exception e1) {
            }
    }
    
}

